/*
 * This file is part of the Boring Engine's Kirby Game.
 *
 * Copyright (c) 2011 by pf5234 <pf5234@users.sourceforge.net>.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

package kirby;

import com.googlecode.boringengine.DefaultFont;
import com.googlecode.boringengine.Font;
import com.googlecode.boringengine.Graphics;
import com.googlecode.boringengine.Menu;
import com.googlecode.boringengine.Render;

public class Inventory extends Menu<Item> {

    @Override
    public void draw() {
        drawScreen();
        super.draw();
    }
    
    @Override
    protected void menuItemClicked(Item item) {
        if (item.use())
            removeItem(item);
    }

    @Override
    protected void draw(Item item, int x, int y, boolean isSelected) {
        Render.moveOverWithoutScale(x, y);
        Font f = DefaultFont.getDefaultFont();
        Graphics.drawSprite(item.getSprite(), 10, 5);
        f.draw(50, 5, item.getType());
        f.draw(50, 21, item.getDescription());
        if (isSelected) {
            Graphics.drawRect(4, 1, 792, 2, 0);
            Graphics.drawRect(4, 38, 792, 2, 0);
            Graphics.drawRect(4, 1, 2, 38, 0);
            Graphics.drawRect(794, 1, 2, 38, 0);
        }
        Render.moveOverWithoutScale(-x, -y);
    }
    
    private Inventory() {
        super(600, 0, 200, 600, 40);
    }

    private static Inventory instance;
    public static Inventory getMenu() {
        if (instance == null) instance = new Inventory();
        return instance;
    }

    public static void add(Item i) {
        getMenu().addItem(i);
    }

    public static void remove(Item i) {
        getMenu().removeItem(i);
    }

}
